﻿using HlELock.Core;
using HlELock.Core.Events;
using HlELock.Core.Models;
using HlELock.Core.Views;
using HlELock.Domain.Entities;
using HlELock.Modules.Hotel.Agency.Views;
using Prism.Commands;
using Prism.Mvvm;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Interop;

namespace HlELock.Modules.Hotel.Agency.ViewModels
{
    public class AgencyPageViewModel : BindableBase
    {
        public AgencyPageViewModel()
        {
        }

        private DelegateCommand _settingCommand;
        public DelegateCommand SettingCommand =>
            _settingCommand ?? (_settingCommand = new DelegateCommand(ExecuteSettingCommand));

        void ExecuteSettingCommand()
        {
            EventBus.ShowDialogWindow(new DialogWindowEventArgs
            {
                Title = "设置扇区",
                Uri = nameof(SettingControl)
            });
        }
        private DelegateCommand _buttonCommand;
        public DelegateCommand ButtonCommand =>
            _buttonCommand ?? (_buttonCommand = new DelegateCommand(ExecuteButtonCommand));

        void ExecuteButtonCommand()
        {
            //if (CurrentHotelInfo == null)
            //{
            //    MessageBox.Show(AppHelper.GetResourceString("XuanZeCaoZuoJiuDian"));
            //    return;
            //}
            //EventBus.ShowDialogWindow(new DialogWindowEventArgs
            //{
            //    Title = "酒店管理",
            //    Uri = nameof(HotelMangeControl),
            //    Parameters = new System.Collections.Generic.Dictionary<string, object>
            //    {
            //        {nameof(HotelInfo),CurrentHotelInfo }
            //    }
            //});
            var dialog = new HotelMangeControl();
            dialog.ShowDialog();
        }
        private DelegateCommand _refreshCommand;
        public DelegateCommand RefreshCommand =>
            _refreshCommand ?? (_refreshCommand = new DelegateCommand(ExecuteRefreshCommand));

        async void ExecuteRefreshCommand()
        {
            var hotels = await HttpHelper.GetHotelsAsync();
            HotelInfos = hotels.ToObservableCollection();
        }
        private DelegateCommand _onLoadCommand;
        public DelegateCommand OnLoadCommand =>
            _onLoadCommand ?? (_onLoadCommand = new DelegateCommand(ExecuteOnLoadCommand));

        async void ExecuteOnLoadCommand()
        {

            var hotels = await HttpHelper.GetHotelsAsync();
            HotelInfos = hotels.ToObservableCollection();

            var title = AppHelper.GetResourceString("SheBeiPeiZhi");
            EventBus.Instace.GetEvent<DialogWindowEvent>().Publish(new Core.Events.DialogWindowEventArgs
            {
                Title = title,
                Uri = "SearchDeviceControl"
            });

        }

        private ObservableCollection<HotelInfo> _hotelInfos;
        public ObservableCollection<HotelInfo> HotelInfos
        {
            get { return _hotelInfos; }
            set { SetProperty(ref _hotelInfos, value); }
        }

        private string _title;
        public string Title
        {
            get { return _title; }
            set { SetProperty(ref _title, value); }
        }
        private HotelInfo _currentHotelInfo;
        public HotelInfo CurrentHotelInfo
        {
            get { return _currentHotelInfo; }
            set { SetProperty(ref _currentHotelInfo, value); }
        }
    }
}
